*WIC co-op eWIC twfe diff in diff analysis
*last modified: 21 December 2024
*last modified by: Kathya Tapia-Schythe
*this do file tabulates twfe and graphs csdid estimated effects of WIC EBT on SNAP and WIC redemptions per county and zip respectively

*-------------------------------------------------------------------------------
*--- Preamble
*-------------------------------------------------------------------------------

clear all
set more off
set rmsg on

set maxvar 120000
set emptycells drop

*ssc install estout, replace

*-------------------------------------------------------------------------------
*--- Directories and Log 
*-------------------------------------------------------------------------------

local data_dir ./data/cleaned
local raw_dir ./data/raw
local out_dir ./analysis/output
local graph_dir ./analysis/output/graphs
local tab_dir ./analysis/output/tables
local log_dir ./documentation/logs
local date: display %tdYY-NN-DD date(c(current_date), "DMY")
di "`date'"
capture log close

log using `log_dir'/tables_figures_lred`date', replace

*-------------------------------------------------------------------------------
*--- TWFE: Table
*-------------------------------------------------------------------------------

foreach out in lzip lcounty {
	
 estimates use `out_dir'/twfe_`out'_simple.ster
 eststo twfe_`out'_simple

 lincom ebt
 local lb = string(r(lb), "%05.3f") // lower bound
 local ub = string(r(ub), "%05.3f") // upper bound

 estadd local ci "[`lb',`ub']": twfe_`out'_simple
 estadd local fy "Yes": twfe_`out'_simple
}

#delimit ;
esttab twfe_lzip_simple twfe_lcounty_simple 
using "`tab_dir'/twfe_lred.tex",
stats(ci fy N, fmt(%05.3f %-5s %9.0gc)
labels(" " "\\ FY FE" "\midrule \textit{N}")) keep(ebt) label
b(%-9.3f) not noobs nonotes nogaps mlabels(, none) nonumbers style(tex)
fragment replace noline starlevel("*" 0.10 "**" 0.05 "***" 0.01)
coef(ebt "WIC EBT");
#delimit cr
estimates clear

*-------------------------------------------------------------------------------
*--- CSDID: Figures
*-------------------------------------------------------------------------------

*ssc install blindschemes, replace 
set scheme plotplainblind
graph set window fontface "Times New Roman"

*a.- WIC
use `out_dir'/csdid_lzip_event.dta, clear

keep if subsample == "all"

#delimit ; 
twoway rarea avgul avgll ev_yr if ev_yr<0,  color(gs9%50) ||
       rarea avgul avgll ev_yr if ev_yr>=0, color(gs9%50) ||
       scatter b  ev_yr, mcolor(black) msymbol(O) msize(medlarge) || 
       rcap ul ll ev_yr, msize(vtiny) lcolor(black)        ||
       line avgb ev_yr if ev_yr<0,  lcolor(gs9) lpattern(solid)  ||
       line avgb ev_yr if ev_yr>=0, lcolor(gs9) lpattern(solid)
       yline(0, lcolor(black) lpattern(dash)) 
       xline(0, lcolor(red) lpattern(dot) lwidth(medthick))
       ytitle("ATT estimate") xtitle("Event Year")
       legend(off);
#delimit cr

graph export "`graph_dir'/csdid_lzip_all.png", replace

*b.- SNAP
use `out_dir'/csdid_lct_event.dta, clear

keep if subsample == "all"

#delimit ; 
twoway rarea avgul avgll ev_yr if ev_yr<0,  color(gs9%50) ||
       rarea avgul avgll ev_yr if ev_yr>=0, color(gs9%50) ||
       scatter b  ev_yr, mcolor(black) msymbol(O) msize(medlarge) || 
       rcap ul ll ev_yr, msize(vtiny) lcolor(black)        ||
       line avgb ev_yr if ev_yr<0,  lcolor(gs9) lpattern(solid)  ||
       line avgb ev_yr if ev_yr>=0, lcolor(gs9) lpattern(solid)
       yline(0, lcolor(black) lpattern(dash)) 
       xline(0, lcolor(red) lpattern(dot) lwidth(medthick))
       ytitle("ATT estimate") xtitle("Event Year")
       legend(off);
#delimit cr
 
graph export "`graph_dir'/csdid_lct_all.png", replace


log close
